// pages/errorsClassify/errorsClassify.js
import api from "../../config/api";
import request from "../../utils/request";
import { shareOptions } from "../../utils/access";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    knowledgeid: '',
    accomplishData:[],
    iconObj:{
      1:'https://image-classify.daieco.com/kejian-quanzi/6aoMxW3J4v1fcb9deee87049004d88d49079c222d6bd.png',
      2:'https://image-classify.daieco.com/kejian-quanzi/quS80IBvDR4m33180e237f68b31f02cff0184e518e68.png',
      3:'https://image-classify.daieco.com/kejian-quanzi/Wzd8w6y9rr0i265b8ed02f939fabb5ded8a43510d817.png',
      4:'https://image-classify.daieco.com/kejian-quanzi/b5s7EYxENWHw7eeda1cad1e8fe882dd122c56fc8ad1c.png',
      5:'https://image-classify.daieco.com/kejian-quanzi/30fUmhq6dOnGbba090832001b726946b3bbdf92e07f6.png'
    },
    isLoaing: false
  },
  // 获取错题类别和数量
  async getAccomplishData(){
    const { iconObj } =this.data;
    const data = await request.get(api.getAccomplishList)
    const list = data.data.map((item)=>{
      return {...item , icon:iconObj[item.knowledgeId] }
    });
    console.log(list)
    this.setData({
      accomplishData:list
    })
  },
  // 点击跳转错题库
  goErrorsStoreroom(e) {
    console.log(e)
    console.log(e.currentTarget.dataset.knowledgeid)
    wx.navigateTo({
      url: `/pages/errorsStoreroom/errorsStoreroom?knowledgeId=${e.currentTarget.dataset.knowledgeid}`,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.setData({
      knowledgeid:''
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getAccomplishData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(e) {
    return shareOptions('default', e)
  }
})